package com.codefish.codefishseckill.mq;

import com.alibaba.fastjson.JSON;
import com.codefish.codefishseckill.config.RabbitMQConfig;
import com.codefish.codefishseckill.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 描述
 *
 * @author codefish
 * @version 1.0
 * @date 2022/07/20 下午 03:16
 */
@Service
@Slf4j
public class MQProducerService {
    @Autowired
    RabbitTemplate rabbitTemplate;

    public void senderOrder(Order order) {
        String orderJsonStr = JSON.toJSONString(order);
        log.info("往MQ中添加订单信息：" + orderJsonStr);

        rabbitTemplate.convertAndSend(RabbitMQConfig.ORDER_QUEUE_NAME, orderJsonStr);
    }
}
